import Vue from 'vue'
import VueRouter from 'vue-router'
import home from './modules/home' // 首页
import sjzcgl from './modules/sjzcgl' // 数据资产管理显示
import jtchsj from './modules/jtchsj' // 集团持续审计专题管理显示
import mxyy from './modules/mxyy' // 模型预研功能展示
import zxsj from './modules/zxsj' // 专项审计支撑管理
import sjmhmx from './modules/sjmhmx' // IT公司审计门户及审计模型演示
import sjgl from './modules/sjgl' // 审计管理任务

Vue.use(VueRouter)

/**
 * 路由相关属性说明
 * hidden: 当设置hidden为true时，意思不在sideBars侧边栏中显示
 * mete{
 *  title: xxx,  设置sideBars侧边栏名称
 *  icon: xxx,  设置ideBars侧边栏图标
 *  noCache: true  当设置为true时不缓存该路由页面
 * }
 */

/* common routers */
export const currencyRoutes = [
  ...home,
  ...sjzcgl,
  ...jtchsj,
  ...mxyy,
  ...zxsj,
  ...sjmhmx,
  ...sjgl,
  {
    path: '/dashboard',
    name: 'dash',
    component: () => import('@/views/home/dashboard'),
    hidden: true
  },
  {
    path: '*',
    name: '404',
    component: () => import('@/views/error-page'),
    hidden: true
  }
]

/* async routers */
export const asyncRoutes = []

const creatRouter = () => {
  return new VueRouter({
    routes: currencyRoutes,
    scrollBehavior() {
      return {
        y: 0
      }
    }
  })
}

const router = creatRouter()

// 解决addRoute不能删除动态路由问题
export function resetRouter() {
  const reset = creatRouter()
  router.matcher = reset.matcher
}

// vue-router 3.x 必需监听 错误
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router
